(* File lexer.mll *)
{
  open Parser        (* The type token is defined in parser.mli *)

  let h = Hashtbl.create 17
  let _ =
    List.iter (fun (k,t) -> Hashtbl.add h k t)
      [
        ("&",AND); ("|",OR);
        ("<>",XOR); ("=",EQ);
        ("=>",IMP); ("!",NOT);
        (",",COM); (";",SC);
      ]

  let key = Hashtbl.create 17
  let _ = List.iter (fun (k,t) -> Hashtbl.add key k t)
    [
      ("none",NONE); ("true",TRUE); ("false",FALSE); ("both",BOTH);
      ("def",DEF); ("fun",FUNC);
      ("begin", BEGIN); ("end",END);
    ]


}
let ident = ['a'-'z']['a'-'z' 'A'-'Z' '_' '0'-'9']*

let white = [' ' '\t' '\n']

let op = "&" | "|" | "<>" | "=" | "=>" | "!" | "," | ";"

rule token = parse
    white+      { token lexbuf }     (* skip blanks *)
  | ident as ato
      { try Hashtbl.find key ato with Not_found -> VAR ato }
  | op          { Hashtbl.find h (Lexing.lexeme lexbuf)}
  | '('         { LPAREN }
  | ')'         { RPAREN }
  | '#'         { comment lexbuf }
  | eof         { EOF }

and comment = parse
  | "\n"        { token lexbuf }
  | _           { comment lexbuf }
